home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / pippki.jar / content / pippki / pref-masterpass.js < prev    next >
Encoding:
Text File  |  2007-01-31  |  4.6 KB  |  122 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Javier Delgadillo <javi@netscape.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. const nsIPK11Token = Components.interfaces.nsIPK11Token;
  41. const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
  42. const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
  43. const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
  44. const nsDialogParamBlock = "@mozilla.org/embedcomp/dialogparam;1";
  45.  
  46. var internal_token;
  47.  
  48. function onMasterPasswordLoad()
  49. {
  50.   var tokendb = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
  51.   internal_token = tokendb.getInternalKeyToken();
  52.   var askTimes = internal_token.getAskPasswordTimes();
  53.   switch (askTimes) {
  54.   case nsIPK11Token.ASK_FIRST_TIME:  askTimes = 0; break;
  55.   case nsIPK11Token.ASK_EVERY_TIME:  askTimes = 1; break;
  56.   case nsIPK11Token.ASK_EXPIRE_TIME: askTimes = 2; break;
  57.   }
  58.   var radiogroup = document.getElementById("passwordAskTimes");
  59.   var radioitem;
  60.   switch (askTimes) {
  61.   case 0: radioitem = document.getElementById("askFirstTime"); break;
  62.   case 1: radioitem = document.getElementById("askEveryTime"); break;
  63.   case 2: radioitem = document.getElementById("askTimeout"); break;
  64.   }
  65.   radiogroup.selectedItem = radioitem;
  66.   var timeout = internal_token.getAskPasswordTimeout();
  67.   var timeoutField = document.getElementById("passwordTimeout");
  68.   timeoutField.setAttribute("value", timeout);
  69.   
  70.   changePasswordSettings(false);
  71. }
  72.  
  73. function changePasswordSettings(setFocus)
  74. {
  75.   var askTimes = 0;
  76.   var timeout = internal_token.getAskPasswordTimeout();
  77.   var timeoutField = document.getElementById("passwordTimeout");
  78.   var radiogroup = document.getElementById("passwordAskTimes");
  79.   switch ( radiogroup.value ) {
  80.   case "0": 
  81.     timeoutField.setAttribute("disabled", true);
  82.     askTimes = nsIPK11Token.ASK_FIRST_TIME;
  83.     break;
  84.   case "1": 
  85.     timeoutField.setAttribute("disabled", true);
  86.     askTimes = nsIPK11Token.ASK_EVERY_TIME;
  87.     break;
  88.   case "2":
  89.     timeoutField.removeAttribute("disabled");
  90.     if ( setFocus ) {
  91.       timeoutField.focus();
  92.     }
  93.     timeout = timeoutField.value;
  94.     var re = new RegExp("^[0-9]+$");
  95.     if (!re.test(timeout)) {
  96.       timeout = "1";
  97.     }
  98.     askTimes = nsIPK11Token.ASK_EXPIRE_TIME;
  99.     break;
  100.   }
  101.   internal_token.setAskPasswordDefaults(askTimes, timeout);
  102.  
  103.   var askEveryTimeHidden = document.getElementById("askEveryTimeHidden");
  104.   askEveryTimeHidden.checked = (radiogroup.value == 1) ? true : false;
  105. }
  106.  
  107. function ChangePW()
  108. {
  109.   var params = Components.classes[nsDialogParamBlock].createInstance(nsIDialogParamBlock);
  110.   params.SetString(1,"");
  111.   window.openDialog("chrome://pippki/content/changepassword.xul","",
  112.                     "chrome,centerscreen,modal",params);
  113. }
  114.  
  115. function ResetPW()
  116. {
  117.   var params = Components.classes[nsDialogParamBlock].createInstance(nsIDialogParamBlock);
  118.   params.SetString(1,internal_token.tokenName);
  119.   window.openDialog("chrome://pippki/content/resetpassword.xul", "",
  120.                     "chrome,centerscreen,modal", params);
  121. }
  122.